//
//  FLLPresentTopicsTableViewCell.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/7.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLPresentTopicsTableViewCell.h"
#import "FLLPresentTopicsCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "FLLMacro.h"

@interface FLLPresentTopicsTableViewCell ()<UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource>

@end
@implementation FLLPresentTopicsTableViewCell

- (void)awakeFromNib {
    // Initialization code
    [self createPresentCollectionView];
}
- (void)createPresentCollectionView
{
    _presentTopicsLayout.minimumInteritemSpacing = CellMargin;
    _presentTopicsLayout.minimumLineSpacing = CellMargin;
    _presentTopicsLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    _presentTopicsLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _presentTopicsCollectionView.delegate = self;
    _presentTopicsCollectionView.dataSource = self;
    _presentTopicsCollectionView.showsHorizontalScrollIndicator = NO;
    _presentTopicsCollectionView.backgroundColor = [UIColor whiteColor];
    [_presentTopicsCollectionView registerNib:[UINib nibWithNibName:@"FLLPresentTopicsCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"presentTopicsCollectionCell"];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return _marrowArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    FLLPresentTopicsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"presentTopicsCollectionCell" forIndexPath:indexPath];
    [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:_marrowArray[indexPath.row].image] placeholderImage:[UIImage new] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];

    return cell;
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat itemWidth = (_presentTopicsCollectionView.bounds.size.width - 2 * CellMargin) / 3.0;
    CGFloat itemHeight = itemWidth;
    return CGSizeMake(itemWidth, itemHeight);
}
- (void)setMarrowArray:(NSArray<PresentShequ_Marrow *> *)marrowArray
{

    _marrowArray = marrowArray;
    [self.presentTopicsCollectionView reloadData];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *idString = self.marrowArray[indexPath.row].id_Data;
    NSLog(@"%@", idString);
    self.idBlock(idString);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
